/*
 * Created on 21.04.2003
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package pho.helper;

import java.util.Iterator;
import java.util.List;

import pho.prowon.index.IndexFactory;
import pho.prowon.index.IndexImplementation;
import cpa.prowon.image.ImageContainer;

/**
 * @author Peter
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class Migrate
{

	public static void main(String[] args)
	{
		
		try
		{
			IndexImplementation index_implementation = IndexFactory.getIndexImplementation();
			List images = index_implementation.readIndex(ImageContainer.class,Boolean.TRUE);
			Iterator it = images.iterator();
			while (it.hasNext())
			{
				ImageContainer ic = (ImageContainer) it.next();
				String [] sc = ic.getImageDataTagArray("SupplementalCategorys");
				String [] scnew = new String [sc.length+1];
				scnew [0] = ic.getImageDataTag("Category");
				for (int i=0;i<sc.length;i++)
				{
					scnew[i+1]=sc[i];
				}
				ic.setImageDataTagArray("SupplementalCategorys", scnew);
				
				System.out.println ("Migrating "+ic.getPathName());
				
				ic.setImageDataTag("Category", "");
				ic.setImageDataTag("Headline",(ic.getImageDataTag("Headline")+" "+ic.getImageDataTag("CaptionAbstract")).trim());
				ic.setImageDataTag("CaptionAbstract",ic.getImageDataTag("Byline"));
				ic.setImageDataTag("Byline","");
				ic.save();
			}
			
		}
		catch (ClassNotFoundException e1)
		{
			e1.printStackTrace();
		}		
	}
}
